<?php
namespace Illuminate\Session\Console;

use Illuminate\Console\Command;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Composer;

class SessionTableCommand extends Command {
    protected $name = 'session:table';
    protected $description = 'Create a migration for the session database table';

    protected $files; // \Illuminate\Filesystem\Filesystem
    protected $composer;

    public function __construct(Filesystem $files, Composer $composer) {
        parent::__construct();

        $this->files = $files;
        $this->composer = $composer;
    }

    public function handle() {
        $fullPath = $this->createBaseMigration();

        $this->files->put($fullPath, $this->files->get(__DIR__.'/stubs/database.stub'));

        $this->info('Migration created successfully!');

        $this->composer->dumpAutoloads(); // 输出自动加载
    }
    protected function createBaseMigration() {
        $name = 'create_sessions_table';

        $path = $this->laravel->databasePath().'/migrations';

        return $this->laravel['migration.creator']->create($name, $path);
    }
}
